package com.tidc.seaserverweb.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.tidc.seaservermodel.entity.Fres;
import com.tidc.seaservermodel.entity.OrderForm;
import com.tidc.seaservermodel.entity.Shop;
import com.tidc.seaservermodel.exception.TidcBadParent;
import com.tidc.seaserverservice.service.SecondaryShopService;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.Map;


@RestController
@RequestMapping("/secondary/shop")
public class SecondaryShopController {
    @Resource
    private SecondaryShopService secondaryShopService;
    @GetMapping("/list")
    public Fres<Map<Object,Object>> getShopList(@RequestParam("pageSize") int pageSize, @RequestParam("pageNum") int pageNum, Authentication authentication) throws TidcBadParent {
        return secondaryShopService.getShopList(pageSize,pageNum,authentication);
    }

    /**
     *
     * @param orderForm 需要 shopId 和 amount
     * @param authentication
     * @return
     * @throws SQLException
     */
    @PostMapping("buy")
    public Fres<String> buyShop(@RequestBody OrderForm orderForm, Authentication authentication) throws SQLException, JsonProcessingException {
        return secondaryShopService.buyShop(orderForm,authentication);
    }
}
